#ifndef TILES_H_
#define TILES_H_


/**
 * Logging macro
 */
#define LOG(fmt, ...)   fprintf(stderr, "%s():%d\t"fmt"\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)

/*
 * Tile naming conventions as per http://wiki.openstreetmap.org/wiki/Tilename
 *+---------------------------------------+------------------------------------------------------------+-------------------------------+
 *|               Name                    |                       URL template                         |         zoomlevels            |
 *+---------------------------------------+------------------------------------------------------------+-------------------------------+
 *| OSM 'standard' style                  | http://[abc].tile.openstreetmap.org/zoom/x/y.png           | 0-19                          |
 *| OpenCycleMap                          | http://[abc].tile.opencyclemap.org/cycle/zoom/x/y.png      | 0-18                          |
 *| OpenCycleMap Transport (experimental) | http://[abc].tile2.opencyclemap.org/transport/zoom/x/y.png | 0-18                          |
 *| MapQuest                              | http://otile[1234].mqcdn.com/tiles/1.0.0/osm/zoom/x/y.jpg  | 0-19                          |
 *| MapQuest Open Aerial                  | http://otile[1234].mqcdn.com/tiles/1.0.0/sat/zoom/x/y.jpg  | 0-11 globally, 12+ in the U.S.|
 *| Migurski's Terrain                    | http://tile.stamen.com/terrain-background/zoom/x/y.jpg     | 4-18, US-only (for now)       |
 *+---------------------------------------+------------------------------------------------------------+-------------------------------+
 */
#define STYLE_OSM_STANDARD          1
#define STYLE_OPEN_CYCLE_MAP        2
#define STYLE_OPEN_CYCLE_TRANSPORT  3
#define STYLE_MAPQUEST              4
#define STYLE_MAPQUEST_AERIAL       5
#define STYLE_MIGURSKI_TERRAIN      6
/**
 * Select the default map style
 */
#define MAP_STYLE                   STYLE_MAPQUEST

#if MAP_STYLE == STYLE_OSM_STANDARD
#define FORMAT_HOST     "%c.tile.openstreetmap.org"
#define FORMAT_GET      "GET /%d/%d/%d.png HTTP/1.1\r\n" \
                        "Host: %s\r\n\r\n"
#define SERVER_FIRST    'a'
#define SERVER_LAST     'c'
#elif MAP_STYLE == STYLE_MAPQUEST
#define FORMAT_HOST     "otile%c.mqcdn.com"
#define FORMAT_GET      "GET /tiles/1.0.0/osm/%d/%d/%d.png HTTP/1.1\r\n" \
                        "Host: %s\r\n\r\n"
#define SERVER_FIRST    '1'
#define SERVER_LAST     '4'
#else
#error Map style not defined
#endif

/**
 * Maximum attempts to load tile before giving up
 */
#define MAX_RETRIES     10

/**
 * SOCKET:
 *
 * macro used to provide portability of code to windows sockets
 */
#define SOCKET int

/**
 * INVALID_SOCKET:
 *
 * macro used to provide portability of code to windows sockets
 * the value to be used when the socket is not valid
 */
#undef  INVALID_SOCKET
#define INVALID_SOCKET  (-1)

/**
 * Buffer size to receive data from the socket
 */
#define DEFAULT_BUFLEN  1024

/**
 * Default TCP port on the server to connect
 */
#define DEFAULT_PORT    "http"


/**
 * @typedef struct int_coord_t
 * A data type to store integer coordinates
 */
typedef struct {
    int x;
    int y;
} int_coord_t;

/**
 * @typedef struct point_t
 * A data type that contains coordinates of a point on the Earth's surface
 */
typedef struct {
    double lat;             // latitude (degrees)
    double lon;             // longitude (degrees)
} point_t;

/**
 * @typedef struct rect_t
 * A data type that defines a rectangle on the Earth's surface
 */
typedef struct {
    point_t left_top;       // left top corner of the rectangle
    point_t right_bott;     // right bottom corner of the rectangle
    int min_zoom;
    int max_zoom;
} rect_t;

/**
 * @typedef struct line_t
 * A data type that defines a straight line on the Earth's surface
 */
typedef struct {
    point_t beg;            // beginning of the line
    point_t end;            // end of the line
    int zoom;
    int thickness;          // thickness of the line (in tiles)
} line_t;

#endif /* TILES_H_ */

